<template>
<view>
<view class="container"> 
<view class="product_list_top">
  <view class="product_list_search" :style="'background:' + defaultColor">
    <view class="product_list_search_left">
      <image class="product_list_search_jiantou" src="https://image1.sansancloud.com/xianhua/2019_4/3/11/47/37_614.jpg?x-oss-process=style/preview_120"></image>
      <text class="product_list_search_value">{{productTypeName}}</text>
    </view>
    <view class="product_list_search_right">
      <view class="product_list_search_item" :data-orderType="item.orderType" :data-index="index" :data-id="item.id" @click.stop="selectSearchType" v-for="(item, index) in productTypeItem" :key="index">
        <text class="product_type">{{item.title}}</text>
        <view class="product_type_state" v-if="item.id!=3">
          <image class="product_type_state_icon activeUp" v-if="item.upState" src="https://image1.sansancloud.com/xianhua/2019_4/3/11/55/16_11.jpg?x-oss-process=style/preview_120"></image>
          <image class="product_type_state_icon up" v-else src="https://image1.sansancloud.com/xianhua/2019_4/3/11/47/26_97.jpg?x-oss-process=style/preview_120"></image>
          <image class="product_type_state_icon activeDown" v-if="item.downState" src="https://image1.sansancloud.com/xianhua/2019_4/3/11/47/37_615.jpg?x-oss-process=style/preview_120"></image>
          <image class="product_type_state_icon down" v-else src="https://image1.sansancloud.com/xianhua/2019_4/3/11/55/15_979.jpg?x-oss-process=style/preview_120"></image>
        </view>
        <view class="product_type_state" v-else>
          <image class="product_promotion_icon" v-if="!item.state" src="https://image1.sansancloud.com/xianhua/2019_4/3/11/55/16_5.jpg?x-oss-process=style/preview_120"></image>
          <image class="product_promotion_icon" v-else src="https://image1.sansancloud.com/xianhua/2019_4/3/11/47/37_600.jpg?x-oss-process=style/preview_120"></image>
        </view>
      </view>
      <!-- <view class='product_list_search_item'>
        <text class='product_type'>活动</text>
        <view class='product_type_state'>
          <image class='product_promotion_icon' src='https://image1.sansancloud.com/xianhua/2019_4/3/11/55/16_5.jpg?x-oss-process=style/preview_120'></image>
          <image class='product_promotion_icon' src='https://image1.sansancloud.com/xianhua/2019_4/3/11/47/37_600.jpg?x-oss-process=style/preview_120'></image>
        </view>
      </view> -->
      <view class="product_search" data-link="search_page.html" @tap="tolinkUrl">
        <image class="product_search_icon" src="https://image1.sansancloud.com/xianhua/2019_4/3/14/13/8_191.jpg?x-oss-process=style/preview_120"></image>
      </view>
    </view>
  </view>
  <view class="product_promotion_list" v-if="productTypeItem[3].state">
    <view class="product_promotion_item" data-itemSpecialSaleType="0" @click.stop="selectPromotionType">
      <text>不限</text>
    </view>
    <view class="product_promotion_item" data-itemSpecialSaleType="2" @click.stop="selectPromotionType">
      <text>买一送一</text>
    </view>
    <view class="product_promotion_item" data-itemSpecialSaleType="1" @click.stop="selectPromotionType">
      <text>买满就送</text>
    </view>
    <view class="product_promotion_item" data-itemSpecialSaleType="3" @click.stop="selectPromotionType">
      <text>限时抢购</text>
    </view>
  </view>
</view>
<!-- 列表 -->
<view :class="(!productTypeItem[3].state?'product_page_container2':'product_page_container2 mt_156')">
    <product-list-component class="productListPage" ></product-list-component>
</view>

  <!-- 首页组件-公共产品分类装饰-->
  <custom-page-index-component :receiveData="sendIndexData" v-if="sendIndexData"></custom-page-index-component>
  
<!-- <component is="measure_card2" :setting="minCount" :focusData="productData.productInfo" :measures="productData.measures" :byNowParams="byNowParams" :measurementJson="measurementJson" :type="bindway"></component> -->
</view>
</view>
</template>

<script>

export default {
  data() {
    return {
      setting: null,
      // setting   
      productListData: [],
      // 商品数据 
      sendData: null,
      sysWidth: 320,
      //图片大小
      searchProductName: "",
      sendProductListData:null,
      /* 显示或影藏 */
      focusTypeItem: null,
      productData: {},
      measurementJson: null,
      byNowParams: {
        productId: '',
        itemCount: 1,
        shopId: '',
        cartesianId: '0',
        chatOrder: '',
        fromSource: '',
        orderType: ''
      },
      MeasureParams: [],
      showCount: false,
      bindway: "",
      reqSearch: false,
      productTypeName: "",
      sendIndexData: null,
      showListType: null,

      /* 全部参数 */
      params: {
        categoryId: "",
        page: 1,
        productName: "",
        orderType: "",
        productTypeId: "",
        itemSpecialSaleType: "0",
        promotionId: "",
        longitude: 0,
        latitude: 0
      },
      productTypeItem:[
        { id: 0, title: "热卖", upState: false, downState: false, orderType: { up: 101, down: 1 }},
        { id: 1, title: "价格", upState: false, downState: false, orderType: { up: 102, down: 2 }},
        { id: 2, title: "折扣", upState: false, downState: false, orderType: { up: 105, down: 5 }},
        { id: 3, title: "活动", state:false},
      ],
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      },
      showType: false,
      bindProductTypeIndex: "",
      defaultColor: "",
      secondColor: "",
      haveMeasuresState: false,
      selectTypeData: "",
      minCount: "",
      countGood: "",
      showGuigeType: false
    };
  },
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("===options===", options);
    let that = this;
    let locationAddressData = wx.getStorageSync('selectAddressData') || '';

    if (locationAddressData) {
      that.params.latitude = locationAddressData.latitude;
      that.params.longitude = locationAddressData.longitude;
    }

    let sendIndexData = JSON.stringify({
      title: 'noTitle',
      url: "product_list",
      params: {}
    });
    that.setData({
      sendIndexData: sendIndexData
    });

    if (options.productName) {
      that.setData({
        searchProductName: options.productName
      });
    }

    if (!!options.productTypeId) {
      options.categoryId = options.productTypeId;
    }

    for (let i in options) {
      for (let j in that.params) {
        if (i.toLowerCase() == j.toLowerCase()) {
          that.params[j] = options[i];
        }
      }
    }

    console.log(that.params);
    that.getData(that.params, 2);
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: getApp().globalData.setting.platformSetting.defaultColor
    }); // wx.setNavigationBarTitle({
    //   title: "奶爸无忧·母婴商超",
    // })

    this.setData({
      setting: getApp().globalData.setting,
      defaultColor: getApp().globalData.setting.platformSetting.defaultColor,
      secondColor: getApp().globalData.setting.platformSetting.secondColor,
      reqSearch: false,
      productTypeItem: this.productTypeItem
    });
    console.log("===app.setting,====", getApp().globalData.setting);
    this.setProductTypeName(options.categoryId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this; // if (that.data.reqSearch) {
    //   //搜索
    //   console.log("从搜索页面返回")
    //   var pages = getCurrentPages();
    //   var currPage = pages[pages.length - 1]; //当前页面
    //   console.log(currPage) //就可以看到data里mydata的值了
    //   console.log("搜索名称", that.data.searchValue)
    //   that.params.productName = that.data.searchValue;
    //   that.setData({ searchProductName: that.data.searchValue })
    //   that.getData(that.params,2);
    // }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.listPage.page = 1;
    this.params.page = 1;
    this.getData(this.params, 2);
    wx.showNavigationBarLoading();
    wx.hideNavigationBarLoading(); //完成停止加载

    wx.stopPullDownRefresh(); //停止下拉刷新
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    console.log("onReachBottom")
    if (that.listPage.totalSize > that.listPage.curPage * that.listPage.pageSize) {
      that.listPage.page++;
      that.params.page++;
      this.getData(this.params);
    }else{
        wx.showToast({
          title: "到底了~",
          image: '/wxcomponents/images/icons/tip.png',
          duration: 1000
        });
    }
  },
  methods: {
    /* 点击遮罩层 */
    closeZhezhao: function () {
      this.showType = false;
      this.setData({
        showType: false,
        bindProductTypeIndex: null,
        showCount: false
      });
    },
    ChangeParam: function (params) {
      var returnParam = "";

      for (let i in params) {
        returnParam += "&" + i + "=" + params[i];
      }

      console.log(returnParam);
      return returnParam;
    },

    /* 获取数据 */
    getData: function (param) {
      var customIndex = getApp().globalData.AddClientUrl("/more_product_list.html", param, 'get', '1'); 
      getApp().globalData.showToastLoading('loading', true);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);
          let data = res.data.result;
          that.listPage.pageSize = res.data.pageSize;
          that.listPage.curPage = res.data.curPage;
          that.listPage.totalSize = res.data.totalSize;
          let dataArr = that.productListData;//that.productListData
          let tagArray = [];

          for (let i = 0; i < data.length; i++) {
            if (data[i].tags && data[i].tags != '') {
              tagArray = data[i].tags.slice(1, -1).split("][");
              data[i].tagArray = tagArray;
            }

            if (data[i].tagPrice > data[i].price) {
              let discount = (Number(data[i].price) / Number(data[i].tagPrice) * 10).toFixed(1);
              data[i].discount = discount;
            }
          }
          console.log("data", data);
          let showListType = null;

          if (data.length != 0 && data[0].productType == 6) {
            showListType = "piaowu";
          } else {
            showListType = "common";
          }
          that.setData({
            showListType: showListType
          });
          if(that.params.page==1){
              dataArr=data
          }else{
              dataArr = dataArr.concat(data);
          }
          console.log("===dataArr===",dataArr)
          console.log("showListType", that.showListType);
          let sendProductListData={};
          sendProductListData.relateBean=dataArr
          if(showListType=='common'){
            sendProductListData.androidTemplate='pupu_product_list_one'
            sendProductListData.jsonData= {count: dataArr.length,showCard: 1}
          }else{
            sendProductListData.androidTemplate='ticket_one_column'
            sendProductListData.jsonData= {count: dataArr.length,showCard: 0}
          }
          console.log("==that.selectComponent===",that.selectComponent(".productListPage"))
          that.selectComponent(".productListPage").setProductListFun(sendProductListData)
          if (!dataArr || dataArr.length == 0) {
            that.setData({
              productListData: null,
            });
          } else {
            if (dataArr == null) {
              dataArr = [];
            }
            that.setData({
              productListData: dataArr
            });
          }

          console.log("datasendData", that.sendData);
          wx.hideLoading();
        },
        fail: function (res) {
          console.log("fail");
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    tolinkUrl: function (e) {
      console.log("===e====", e);
      let info = e.currentTarget.dataset.info;
      let linkUrl;
      let id = info && info.id || "";

      if (info) {
        if (info.productType == 6) {
          linkUrl = "ticket_detail.html?productId=" + info.id;
        } else {
          linkUrl = "product_detail.html?productId=" + info.id;
        }
      } else {
        linkUrl = e.currentTarget.dataset.link;
      }

      if (linkUrl == "search_page.html") {
        this.setData({
          reqSearch: true
        });
      }

      getApp().globalData.linkEvent(linkUrl);
    },
    selectPromotionType: function (e) {
      console.log("====selectPromotionType====", e);
      let that = this;
      let itemSpecialSaleType = e.currentTarget.dataset.itemspecialsaletype || 0;
      that.params.itemSpecialSaleType = itemSpecialSaleType;
      that.getData(that.params, 2);
    },
    selectSearchType: function (e) {
      console.log("====selectSearchType====", e);
      let that = this;
      let index = e.currentTarget.dataset.index || 0;
      let id = e.currentTarget.dataset.id || 0;
      let orderType = e.currentTarget.dataset.ordertype || {};
      console.log("===orderType===", orderType);

      for (let i = 0; i < that.productTypeItem.length; i++) {
        if (that.productTypeItem[i].id != 3 && i != index) {
          that.productTypeItem[i].upState = false;
          that.productTypeItem[i].downState = false;
        }
      }

      if (!that.productTypeItem[index].upState && !that.productTypeItem[index].downState && index != 3) {
        that.productTypeItem[index].upState = true;
        that.params.orderType = orderType.up;
      } else if (that.productTypeItem[index].upState && !that.productTypeItem[index].downState && index != 3) {
        that.productTypeItem[index].upState = false;
        that.productTypeItem[index].downState = true;
        that.params.orderType = orderType.down;
      } else if (index == 3) {
        if (that.productTypeItem[index].state) {
          that.productTypeItem[index].state = false;
        } else {
          that.productTypeItem[index].state = true;
        }
      } else {
        that.params.orderType = 0;
        that.productTypeItem[index].downState = false;
        that.productTypeItem[index].upState = false;
      }

      that.setData({
        productTypeItem: that.productTypeItem
      });

      if (index != 3) {
        that.params.page = 1;
        that.getData(that.params, 2);
      }
    },
    toProductDetail: function (event) {
      console.log("--------toProductDetail------");
      console.log(event.currentTarget.dataset.info);
      var info = event.currentTarget.dataset.info;
      wx.navigateTo({
        url: '../productDetail/index?id=' + info.id + "&addShopId=" + info.belongShopId
      });
    },
    setProductTypeName: function (id) {
      let that = this;
      let categories = getApp().globalData.setting.platformSetting.categories;

      if (id == 0 || !id) {
        that.setData({
          productTypeName: "全部"
        });
      } else {
        for (let i = 0; i < categories.length; i++) {
          if (categories[i].id == id) {
            that.setData({
              productTypeName: categories[i].name
            });
          }
        }
      }
    },
    /* 立即购买 */
    buyNow: function (e) {
      console.log("==buyNow==", e);

      if (!getApp().globalData.checkShopOpenTime()) {
        return;
      }

      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      let bindway;

      if (e.currentTarget.dataset.way) {
        bindway = e.currentTarget.dataset.way;
      } else {
        bindway = this.bindway;
      }

      console.log('=======bindway======', bindway);
      this.setData({
        haveMeasuresState: true
      });
      this.setData({
        selectTypeData: this.selectTypeData
      });
      console.log('-----------addtocart----------');
      this.addtocart();
    },
    // 这里是一个自定义方法
    readyAddCar: function (e) {
      let that = this;
      console.log("====readyAddCar=====", e);
      console.log("====byNowParams=====", that.byNowParams);
      let productInfo = e.currentTarget.dataset.product;
      that.productData.productInfo = productInfo;
      that.setData({
        productData: that.productData
      });
      console.log("====productData=====", that.productData);
      console.log("====productInfo.id=====", productInfo.id);
      that.get_product_measureFun(productInfo.id);
    },
    subNum: function () {
      if (this.measurementJson.id) {
        this.setData({
          minCount: this.measurementJson.minSaleCount
        });
      } else {
        this.setData({
          minCount: 1
        });
      }

      if (this.byNowParams.itemCount == this.minCount) {
        return;
      }

      this.byNowParams.itemCount--;
      this.setData({
        byNowParams: this.byNowParams
      });
    },
    addNum: function () {
      this.byNowParams.itemCount++;
      this.setData({
        byNowParams: this.byNowParams
      });
    },
    addtocart: function () {
      console.log("===addtocart====");

      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      var params = {
        cartesianId: '',
        productId: '',
        shopId: '',
        count: '',
        type: ''
      };

      if (this.productData.measures.length == 0) {
        params.cartesianId = '0';
      } else {
        params.cartesianId = this.measurementJson.id;
      }

      params.productId = this.productData.productInfo.id;
      params.shopId = this.productData.productInfo.belongShopId;
      params.count = this.byNowParams.itemCount;
      params.type = 'add';
      console.log('===postParams=====', params);
      this.postParams(params);
    },
    postParams: function (data) {
      console.log("==postParams====");
      var that = this;
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('---------------change_shopping_car_item-----------------');
          console.log(res.data);
          wx.hideLoading();

          if (that.bindway == 'cart') {
            that.setData({
              showCount: false
            });
          }

          if (data.productId == 0) {
            console.log('购物车里面的商品数量');
            that.setData({
              countGood: res.data.totalCarItemCount
            });
          } else {
            if (res.data.productId && res.data.productId != 0) {
              if (data.count == 0) {
                console.log('通过加入购物车来确定购物车里面的商品数量');
              } else {
                wx.showToast({
                  title: '加入购物车成功'
                });
              }

              if (!!res.data.totalCarItemCount || res.data.totalCarItemCount == 0) {
                that.setData({
                  countGood: res.data.totalCarItemCount
                });
              }
            } else {
              wx.showToast({
                title: res.data.errMsg,
                image: '/wxcomponents/images/icons/tip.png',
                duration: 2000
              });
            }
          }

          try {
            getApp().globalData.carChangeNotify(res.data);
          } catch (e) {}
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },

    /* 
       规格操作
    */
    //提交规格产品
    submitMeasure: function (id) {
      var that = this;
      let focusProduct = this.MeasureItem;
      let measurementJson = this.measurementJson;
      let data = {};
      data.cartesianId = measurementJson.id;
      data.productId = focusProduct.id;
      data.shopId = focusProduct.belongShopId;
      data.count = 1;
      data.type = 'add';
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('--------add----------');
          console.log(res.data);
          that.setData({
            showGuigeType: false
          });
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    //获取规格价格参数
    get_measure_cartesionFun: function () {
      this.setData({
        measurementJson: {
          waitDataState: false
        }
      });
      let productId = this.productData.productInfo.id;
      let postStr = '';

      if (this.MeasureParams.length == 0) {
        this.byNowParams.cartesianId = '0';
        this.setData({
          measurementJson: {
            waitDataState: true
          }
        }); //没有规格时 不需要等待请求

        return;
      }

      for (let i = 0; i < this.MeasureParams.length; i++) {
        postStr += this.MeasureParams[i].value + ',';
      }

      let param = {};
      param.productId = productId;
      param.measureIds = postStr;
      console.log(postStr);
      let customIndex = getApp().globalData.AddClientUrl("/get_measure_cartesion.html", param);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("===measurementJson===", res.data);
          that.byNowParams.cartesianId = res.data.id;
          that.setData({
            measurementJson: res.data
          });
          that.measurementJson.waitDataState = true;
          that.setData({
            measurementJson: that.measurementJson
          });
          that.byNowParams.itemCount = that.measurementJson.minSaleCount;
          that.setData({
            minCount: that.byNowParams.itemCount
          });
          that.setData({
            byNowParams: that.byNowParams
          });
        },
        fail: function (res) {
          console.log("fail");
          getApp().globalData.loadFail();
        },
        complete: function () {}
      });
    },
    //获取规格价格参数
    get_product_measureFun: function (id) {
      let that = this;
      let productId = id;
      let customIndex = getApp().globalData.AddClientUrl("/get_product_measures.html", {
        productId: productId
      });
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);
          let measures = res.data;
          that.productData.measures = measures;
          that.setData({
            productData: that.productData
          });

          if (measures.length == 0) {
            that.addtocart();
          } else {
            that.setData({
              bindway: "cart"
            });
            that.setData({
              showCount: true
            });
            let info = that.productData.productInfo;
            that.byNowParams.productId = info.id;
            that.byNowParams.shopId = info.belongShopId;
            that.byNowParams.orderType = 0;
            that.setData({
              byNowParams: that.byNowParams
            });
            console.log("==byNowParams===", that.byNowParams);
            that.chooseMeasureItem();
          }
        },
        fail: function (res) {
          console.log("fail");
          getApp().globalData.loadFail();
        },
        complete: function () {}
      });
    },

    /* 初始化 选规格 */
    chooseMeasureItem: function (event) {
      console.log('----------初始化规格参数-----------', event);
      let that = this;
      let productData = that.productData;
      let focusProduct = productData;
      let selectTypeData = [];

      for (let i = 0; i < focusProduct.measures.length; i++) {
        focusProduct.measures[i].checkedMeasureItem = 0; //初始化选择的数据

        let param = {};
        let selectTypeDataItem = {};
        param.name = focusProduct.measures[i].name;
        param.value = focusProduct.measures[i].productAssignMeasure[0].id;
        selectTypeDataItem.type = focusProduct.measures[i].name;
        selectTypeDataItem.value = focusProduct.measures[i].productAssignMeasure[0].measureName;
        console.log('=====param=====', param);
        that.MeasureParams.push(param);
        selectTypeData.push(selectTypeDataItem);
      }

      that.selectTypeData = selectTypeData;
      console.log('====that.data.selectTypeData======', this.selectTypeData);
      that.setData({
        productData: focusProduct
      });
      console.log('===MeasureParams====', this.MeasureParams);
      that.get_measure_cartesionFun();
    },
    //选择规格小巷的---显示
    radioChange: function (e) {
      let that = this;
      let flag = false;
      console.log("====radioChange=====", e);
      console.log('====that.data.selectTypeData======', that.selectTypeData);

      if (that.selectTypeData) {
        console.log('1111111');

        for (let i = 0; i < that.selectTypeData.length; i++) {
          if (e.currentTarget.dataset.type == that.selectTypeData[i].type) {
            that.selectTypeData.splice(i, 1, e.currentTarget.dataset);
            flag = true;
          }
        }

        if (!flag) {
          that.selectTypeData.splice(that.selectTypeData.length, 1, e.currentTarget.dataset);
          flag = false;
        }
      } else {
        console.log('222222');
        that.selectTypeData = [];
        that.selectTypeData.splice(0, 1, e.currentTarget.dataset);
        that.setData({
          selectTypeData: that.selectTypeData
        });
      }

      console.log('====that.data.selectTypeData======', that.selectTypeData);
      let index = e.currentTarget.dataset.index;
      let indexJson = getApp().globalData.getSpaceStr(index, '-'); //console.log(indexJson)

      let focusItem = that.productData;
      focusItem.measures[indexJson.str1].checkedMeasureItem = indexJson.str2;
      that.setData({
        productData: focusItem
      });
    },
    //选择规格小巷---获取数据
    chooseMeasure: function (e) {
      console.log(e.detail.value);
      let chooseMeasureJson = getApp().globalData.getSpaceStr(e.detail.value, '-');
      console.log(chooseMeasureJson);

      for (let i = 0; i < this.MeasureParams.length; i++) {
        if (this.MeasureParams[i].name == chooseMeasureJson.str1) {
          this.MeasureParams[i].value = chooseMeasureJson.str2;
        }
      }

      this.get_measure_cartesionFun();
    },
    closeGuigeZhezhao: function () {
      this.setData({
        showGuigeType: false
      });
      this.MeasureParams = [];
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>